#include "No7pch.h"
#include "LayerStack.h"

nmspc::LayerStack::LayerStack()
{
}

nmspc::LayerStack::~LayerStack()
{
	for (Layer* layer : this->layers)
	{
		delete layer;
	}
}

void nmspc::LayerStack::pushLayer(nmspc::Layer* layer)
{
	this->layers.emplace(this->layers.begin() + this->layer_insert_index, layer);
	this->layer_insert_index++;
}

void nmspc::LayerStack::pushOverlay(nmspc::Layer* overlay)
{
	this->layers.emplace_back(overlay);
}

void nmspc::LayerStack::popLayer(nmspc::Layer* layer)
{
	auto iter = std::find(this->layers.begin(), this->layers.end(), layer);
	if (iter != this->layers.end())
	{
		this->layers.erase(iter);
		this->layer_insert_index--;
	}
}

void nmspc::LayerStack::popOverlay(nmspc::Layer* overlay)
{
	auto iter = std::find(this->layers.begin(), this->layers.end(), overlay);
	if (iter != this->layers.end())
	{
		this->layers.erase(iter);
	}
}
